import com.weirdor.elasticsearch.kit.ElasticSearchKit;
import com.weirdor.elasticsearch.kit.ElasticSearchQuery;
import com.weirdor.elasticsearch.plugin.ElasticSearchPlugin;
import org.elasticsearch.client.transport.TransportClient;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



/**
 * Created by weirdor on 2017/12/18.
 */
public class a {
    private static Logger logger = LoggerFactory.getLogger(a.class.getName());

    @Before
    public void init() {
        ElasticSearchPlugin elasticSearchPlugin = new ElasticSearchPlugin();
        elasticSearchPlugin.opition();
        elasticSearchPlugin.add("39.106.119.195");
        TransportClient transportClient = elasticSearchPlugin.getTransportClient();
        ElasticSearchKit.INSTANCE.init(transportClient);
    }

    @Test
    public void testPrepareSearch() throws Exception {
        String json = "{" +
                "\"user\":\"weirdorw\"," +
                "\"postDate\":\"2017-12-19\"," +
                "\"message\":\"trying out Elasticsearch\"" +
                "}";


        ElasticSearchQuery elasticSearchQuery = new ElasticSearchQuery();
        Blog b = new Blog();
        b.setName("1");
        b.setPass("pass");
//        Map<String,Object> map=new HashMap<>();
//        map.put("a","b");
//        map.put("b","c");
//        List<ElasticSearchBean> list=new ArrayList<>();
//       ElasticSearchBean bean=new ElasticSearchBean();
//       list.add(new ElasticSearchBean(json));
//        map.put("c",list);


          elasticSearchQuery.use("test","test").set(json).set("name","zhou").set("age",10).save();
        //  elasticSearchQuery.use("test","test").set("name","zhou").save();
        //  elasticSearchQuery.use("test","test").match("name","zhou").delete();
        // elasticSearchQuery.use("test","test").matchPhrase("user","weirdorw").set("message","你好").update();

//        elasticSearchQuery.use("test", "test").set(b).update();
//        And.on(And.on()).createQuery();
//       elasticSearchQuery.use("fendodate","wesd").eq("user","weirdorw").eq("postDate","AWByjwGsnQR3HWLiqu7V").delete();
//        Set<Map<String,Object>> set=new HashSet<>();
//        Map<String,Object> map=new HashMap<>();
//        map.put("_id","AWByiPrlnQR3HWLiqu7Q");
//        set.add(map);
//        ElasticSearchKit.update("wesd","fendodate",set,new Script("id").toString());
    }

}
